<?php // $Id: chat.php 11215 2007-02-26 10:29:11Z elixir_julian $
/*
==============================================================================
	Dokeos - elearning and course management software

	Copyright (c) 2004 Dokeos S.A.
	Copyright (c) 2003 Ghent University (UGent)
	Copyright (c) 2001 Universite catholique de Louvain (UCL)
	Copyright (c) Olivier Brouckaert

	For a full list of contributors, see "credits.txt".
	The full license can be read in "license.txt".

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	See the GNU General Public License for more details.

	Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
==============================================================================
*/
/**
==============================================================================
*	Frameset of the Chat tool
*
*	@author Olivier Brouckaert
*	@package dokeos.chat
==============================================================================
*/

$language_file = array ('chat');
include('../inc/global.inc.php');
$nameTools=get_lang('Chat');
//if ($_GET["origin"] != 'whoisonline') {
//	api_protect_course_script();
//}
//else
//{
	$origin = $_SESSION['origin'];
	$target = $_SESSION['target'];
	$_SESSION['origin']=$_GET["origin"];
	$_SESSION['target']=$_GET["target"];
//}
/* ============================================================================== 
  			TRACKING
==============================================================================  */
include('../inc/lib/events.lib.inc.php');
event_access_tool(TOOL_CHAT);

$used_stylesheet=api_get_setting('stylesheets');

switch($used_stylesheet){
	case 'default' : 
		$footer_size = 48;
		break;
	case 'academica' : 
		$footer_size = 140;
		break;
	case 'corporativa' : 
		$footer_size = 60;
		break;
	case 'baby' : 
		$footer_size = 50;
		break;
	default : 
		$footer_size = 48;
		break;
}

// Connected?
if(isset($_GET['id']))
{
	$chatroomId = $_GET['id'];
	// First time?
	global $_user;
	$table = Database::get_main_table("chatroom_user");
	$query = "SELECT last_connection FROM $table WHERE chatroom_id = $chatroomId AND user_id = $_user[user_id];";
	//echo $query;
	$result = api_sql_query($query, __FILE__, __LINE__);
	if($result)
	{
		if(mysql_num_rows($result) == 0) // first time
			$query = "INSERT INTO $table VALUES($chatroomId, $_user[user_id], NOW(), 'y', NOW());";
		else // update last connected
		{
			// Accepting invitation?
			if(isset($_GET['act']) && $_GET['act'] == "accept")
				$update = "accepted = 'y',";
			else
				$update = "";
			$query = "UPDATE $table SET $update last_connection = NOW() WHERE chatroom_id = $chatroomId AND user_id = $_user[user_id];";
		}
		//echo $query;
		$result = api_sql_query($query, __FILE__, __LINE__);
	}
}
?>
<frameset rows="115,*,<?php echo $footer_size;?>" border="0" frameborder="0" framespacing="1">
	<frame src="chat_banner.php" name="chat_banner" scrolling="no">
	<frameset cols="200,*,0" border="1" frameborder="1" framespacing="1">
		<frame src="chat_whoisonline.php<?php if(isset($_GET['id'])) echo "?id=$_GET[id]"; ?>" name="chat_whoisonline" scrolling="auto">
		<frameset rows="68,22" border="1" frameborder="1" framespacing="1">
			<frame src="<?php echo (isset($_GET['id']) ? "chat_chat.php?id=$_GET[id]" : "chat_list.php"); ?>" name="chat_chat" scrolling="auto">
<?php
if(isset($_GET['id'])):
?>
			<frame src="chat_message.php?id=<?php echo $_GET['id']; ?>" name="chat_message" scrolling="yes">
<?php
endif;
?>
		</frameset>
<?php
if(isset($_GET['id'])):
?>
		<frame src="chat_hidden.php<?php echo "?id=$_GET[id]"; ?>" name="chat_hidden" scrolling="no">
<?php
else:
?>
		<frame src="chat_list_hidden.php" name="chat_list_hidden" scrolling="no">
<?php
endif;
?>
	</frameset>
	<frame src="chat_footer.php" name="chat_footer" scrolling="no">
</frameset>
</html>
